import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

const Store = new Vuex.Store({
    state: {
        /**
         * 是否需要强制登录
         */
        // forcedLogin: false,
        userInfo: {}, //用户信息
        loginStatus: 0, //登录状态,
        loginInfo:{},//登录信息，工号 密码
		TabBarBadge:'',
		location:{},//巡检人员当前所在位置信息，上报位置用
    },
    getters: {
		user_location(state){
			return state.location
		},
        login_Status(state) {
        	return state.loginStatus
        },
        user_Info(state) {
        	return state.userInfo;
        },
        login_Info(state) {
        	return state.loginInfo;
        },
    },
    mutations: {
		SETUSERlOCATION(state, options){
			state.location = options
		},
		SETTABBARBADGE(state, options){
			state.TabBarBadge = options
		},
        setLoginStatus(state, options) {
        	state.loginStatus = options
        },
        setUserInfo(state, options) {
        	state.userInfo = options
        },
        setLoginInfo(state, options) {
        	state.loginInfo = options
        },
        clearUserInfo(state, payload) {
            state.userInfo = {}
			state.loginInfo = {}
			state.loginStatus = 0
        }
    },
    actions: {
        setUserInfo(context, options) {
            context.commit('setUserInfo')
        }
    },
    plugins: [
        createPersistedState({
            storage: {
                getItem: key => wx.getStorageSync(key),
                setItem: (key, value) => wx.setStorageSync(key, value),
                removeItem: key => {}
            }
        })
    ]
})

/*
let _store = new Vuex.Store(Store)
export default _store*/

export default Store